package com.huawei123.hasee.cniao5store.adapter.top;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.huawei123.hasee.cniao5store.R;
import com.huawei123.hasee.cniao5store.bean.CategoryBean;
import com.zhxu.recyclerview.App;

import java.util.List;

/**
 * 项目名称：Cniao5Store
 * 类描述：分类页面头部四按键适配器
 * 创建人：luohao
 * 创建时间：2018/2/4 18:09
 * 修改人：luohao
 * 修改时间：2018/2/4 18:09
 * 修改备注：
 */

public class CategoryAubAdapter extends BaseAdapter {

    private final Context context;
    private final List<CategoryBean.CategoryTopBean> dataBeanList;

    public CategoryAubAdapter(Context context, List<CategoryBean.CategoryTopBean> dataBeanList) {
        this.context = context;
        this.dataBeanList = dataBeanList;
    }

    @Override
    public int getCount() {
        return dataBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CategoryBean.CategoryTopBean categoryTopBean = dataBeanList.get(position);
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.appdetail_subcat_title, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.mTV_ItemTitle.setText(categoryTopBean.getName());
        Glide.with(App.getContext()).load(categoryTopBean.getIconUrl()).into(holder.mIV_appicon);
        return convertView;
    }

    public class ViewHolder {
        TextView mTV_ItemTitle;
        ImageView mIV_appicon;

        public ViewHolder(View itemView) {
            mIV_appicon = (ImageView) itemView.findViewById(R.id.mIV_appicon);
            mTV_ItemTitle = (TextView) itemView.findViewById(R.id.mTV_ItemTitle);
        }
    }
}
